package apiday08.homework;

import java.lang.reflect.Method;
import java.util.Scanner;

public class ReflectDemo1 {
    public static void main(String[] args) throws Exception {
        Class cls = String.class;
        String line = cls.getName();
        System.out.println("String类的完全限定名："+line);
        line = cls.getSimpleName();
        System.out.println("类名："+line);

        Scanner sc = new Scanner(System.in);
        String str = "apiday08.homework.";
        System.out.println("请输入类名：");
        line =  sc.nextLine();
        Class cls1 = Class.forName(str + line);
        System.out.println(cls1.getSimpleName()+"类的完全限定名："+cls1.getName());
        Package pack = cls1.getPackage();
        System.out.println("所在包的包名:"+pack.getName());

        Method[] methods = cls1.getMethods();
        System.out.println(cls1.getSimpleName()+"共有"+methods.length+"个方法");
        for (Method method : methods){
            System.out.println(method.getName());
        }
        Object obj = cls1.newInstance();
        System.out.println("对象信息："+obj);
        sc.close();
    }
}
